import 'package:fluro_decorate/fluro_decorate.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

///
/// @ProjectName:    fluro_demo
/// @Package:
/// @ClassName:      one_page
/// @Description:    dart文件作用
/// @Author:         WTT
/// @CreateDate:     2021/10/27 6:00 下午
class OnePage extends StatefulWidget {
  final int id;

  OnePage(this.id);

  @override
  State<StatefulWidget> createState() => _OnePageState();
}

class _OnePageState extends State<OnePage> {
  Bundle bundle;

  @override
  Widget build(BuildContext context) {
    return SafeArea(
      child: Scaffold(
        body: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Text("我是第一页"),
            if (bundle != null) Text("ONE PAGE: ${bundle.toString()}"),
            Container(
              child: TextButton(
                  child: Text("返回"),
                  onPressed: () {
                    Bundle bundle = Bundle();
                    bundle.putBool("bool", true);
                    bundle.putInt("int", DateTime.now().second);
                    bundle.putString("string", DateTime.now().toString());
                    NavigatorUtil.pop(context, bundle: bundle);
                  }),
            ),
            Container(
              child: TextButton(
                child: Text("缓存当前页面并跳转下一页"),
                onPressed: () {
                  NavigatorUtil.pushNamed(context, "/twoPage",
                          cacheCurrent: true)
                      .then((value) {
                    print("twoPage 返回值是个啥：$value");
                    if (value is Bundle) {
                      this.bundle = value;
                      setState(() {});
                    }
                  });
                },
              ),
            ),
          ],
        ),
      ),
    );
  }
}
